package org.jflame.devAide.component;

import org.jflame.devAide.util.ResourceUtils;

import javafx.beans.property.StringProperty;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;

public class Note extends VBox {

    private TextField title;
    private WebEditor editor;
    private NoteInfo noteInfo;
    // private ScheduledExecutorService saveService = Executors.newSingleThreadScheduledExecutor();

    public Note(NoteInfo _noteInfo) {
        getStyleClass().add("note");
        this.noteInfo = _noteInfo;

        title = new TextField(noteInfo.getTitle());
        title.setPromptText(ResourceUtils.getString("note.untitled"));
        title.getStyleClass()
                .add("title-field");

        editor = new WebEditor("");
        VBox.setVgrow(editor, Priority.ALWAYS);
        getChildren().addAll(title, editor);

        noteInfo.titleProperty()
                .bindBidirectional(title.textProperty());
        requestLayout();
    }

    public Note() {
        this(new NoteInfo());
    }

    public void save() {
    }

    public StringProperty titleProperty() {
        return title.textProperty();
    }

    private void registerHostKey() {
        KeyCombination keyNewNote = new KeyCodeCombination(KeyCode.S, KeyCombination.SHORTCUT_DOWN);
        getScene().getAccelerators()
                .put(keyNewNote, new Runnable() {

                    @Override
                    public void run() {
                        save();
                    }
                });
    }

    /* @Override
    public void initialize(URL location, ResourceBundle resources) {
        System.out.println("注册热键");
        registerHostKey();
    
    }*/

}
